﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DanhSachMucRaoVatCon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        int intId = -1;

        if (Request.QueryString["id"] != null)
        {
            intId = Int32.Parse(Request.QueryString["id"]);
        }
        else
        {
            return;
        }

        LinQ_RaoVatDataContext linQ = new LinQ_RaoVatDataContext();

        var query = from DANH_MUC_CON in linQ.DANH_MUC_CONs where DANH_MUC_CON.MaDanhMucChinh == intId && DANH_MUC_CON.Deleted == false orderby DANH_MUC_CON.TenDanhMucCon ascending select DANH_MUC_CON;
        var KiemTraDMC = from DanhMucChinh in linQ.DANH_MUC_CHINHs where DanhMucChinh.MaDanhMucChinh == intId && DanhMucChinh.Deleted == false select DanhMucChinh;
        if (KiemTraDMC.Count() == 0)
        {
            Response.Write("<script> alert('Thông tin này đã bị xóa');</script>");
        }
        else if (query.Count() == 0)
        {
            Response.Write("<script> alert('Chưa nhập danh mục con của danh mục chính này');</script>");
        }
        else
        {
            GridView1.DataSource = query;
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DANH_MUC_CON objTin = (DANH_MUC_CON)e.Row.DataItem;
            HyperLink hplTenDanhMucCon = (HyperLink)e.Row.FindControl("hplTenDanhMucCon");
            hplTenDanhMucCon.Text = objTin.TenDanhMucCon;
            hplTenDanhMucCon.NavigateUrl = "~/RaoVat/DanhSachTinRaoVatThuocDanhMucCon.aspx?id=" + objTin.MaDanhMucCon;
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
